package com.yl.qunai_kotlin

import android.app.Application
import android.content.Context
import androidx.multidex.MultiDex
import com.tencent.mmkv.MMKV
import com.yl.common.util.ToastUtil
import com.yl.conference.di.conferenceModule
import com.yl.home.di.homeModule
import com.yl.message.di.messageModule
import com.yl.mine.di.mineModule
import org.koin.android.ext.koin.androidContext
import org.koin.android.ext.koin.androidLogger
import org.koin.core.context.GlobalContext
import org.koin.core.logger.Level

class MainApp : Application() {
    private val modules =
        mutableListOf(homeModule, conferenceModule, messageModule, mineModule)

    override fun onCreate() {
        super.onCreate()
        initToast()
        initMMKV()
        initKoin()
    }

    private fun initToast() {
        ToastUtil.init(this)
    }

    override fun attachBaseContext(base: Context?) {
        super.attachBaseContext(base)
        MultiDex.install(base)
    }

    private fun initMMKV() {
        MMKV.initialize(this)
    }

    private fun initKoin() {
        GlobalContext.startKoin {
            androidLogger(Level.NONE)
            androidContext(this@MainApp)
            modules(modules)
        }
    }
}